package com.FindMyStuff.Model;

public class InputChecker {

	/**
	 * A simple check on the values of the editboxes
	 * @return true if there is a problem
	 */
	public static String simpleCheckOnInputs(String reward, ItemType itemType, String name, String location, String description) {
		if(reward == null || itemType == null || name == null || location == null || description == null)
		{
			return "Please Fill Out All of the Fields";
		}
		if(reward.length() == 0)
		{
			if(itemType.equals(ItemType.Lost))
			{
				return "Please Fill Out All of the Fields";
			}
		}
		if(name.length() == 0 || location.length() == 0 || description.length() == 0 )
		{		
			return "Please Fill Out All of the Fields";
		}
		return "";
	}
	
	/**
	 * Checks the email address that is passed in
	 * using regular expressions
	 * @param email The email to be checked
	 * @return true if valid, else false
	 */
	
	public static boolean checkEmail(String email){
		if(email == null)
		{
			return false;
		}
		if(email.equals("admin"))
		{
			return true;
		}
		return email.matches("[A-Za-z0-9]+[@][A-Za-z0-9]+(.com|.net|.edu)");
	}
	
	/**
	 * Checks the reward String to make sure it matches a number format
	 * @param reward
	 * @return
	 */
	public static boolean checkReward(String reward)
	{
		if(reward == null)
		{
			return false;
		}
		if(reward.matches("[\\d]*.[\\d]+")) {
			return true;
		}
		if(reward.matches("[\\d]+[.]?[\\d]*")) {
			return true;
		}
		return false;
	}

	public static String removeQuotes(String string) {
		if(string == null)
		{
			return "";
		}
		if(string.contains("\""))
		{
			return string.replace("\"", "");
		}
		return string;
	}
	
	/**
	 * Checks a given password and returns any errors that are found
	 * 
	 * @param password The password to be checked
	 * @param confirm Contents of the confirm password box
	 * @return A string of the errors found
	 */
	
	public static String checkPassword(String password, String confirm){
		String errors = "";
		if(password == null || confirm == null)
		{
			return errors;
		}
		if(!password.equals(confirm)){
			errors +="Passwords do not match.\n";
		}
		if(password.length()<5 || password.length()>13){
			errors += "Password should be between 5 and 13 characters.\n";
		}
		//regular expression for uppercase and lowercase letters
		//and numbers
		if(!password.matches("[A-Za-z0-9]*")){
			errors += "Password should only be made of letters and numbers.\n";
		}
		
		return errors;
	}
}
